package com.heima.controller;


import com.heima.pojo.dto.RegionAddDto;
import com.heima.pojo.dto.RegionSearchDto;
import com.heima.pojo.vo.PageResponseVo;
import com.heima.pojo.vo.RegionVo;
import com.heima.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 区域管理接口
 */

@RestController
@RequestMapping("/api/vm-service/region")
public class RegionController {

    @Autowired
    private RegionService regionService;

    //分页搜索区域  根据区域名称条件动态搜索
    @GetMapping("/search")
    public PageResponseVo<RegionVo> searchRegion(RegionSearchDto regionSearchDto){
        return regionService.searchRegion(regionSearchDto.getPageIndex(),regionSearchDto.getPageSize(),regionSearchDto.getName());
    }

    //新增区域
    @PostMapping
    public boolean addRegion(@RequestBody RegionAddDto regionAddDto){
        return regionService.addRegion(regionAddDto);
    }

    //修改区域
    @PutMapping("/{regionId}")
    public boolean updateRegion(@PathVariable String regionId,@RequestBody RegionAddDto regionAddDto){
      return regionService.updateRegion(Long.valueOf(regionId),regionAddDto);
    }
    //删除区域
    @DeleteMapping("/{regionId}")
    public boolean deleteRegion(@PathVariable String regionId){
        return regionService.deleteRegionById(Long.valueOf(regionId));
    }
}
